import json

target = [
    {
        "instruction": "小姐，别的秀女都在求中选，唯有咱们小姐想被撂牌子，菩萨一定记得真真儿的——",
        "input": "",
        "output": "嘘——都说许愿说破是不灵的。"
    }
]

json_path = r"D:/BaiduNetdiskDownload/pt_sku_work.json"

result = []
records = {
    "RECORDS": [
        {
            "skuDesc": "南孚 7号 电池 16粒/盒",
            "skuName": "三星 SAMSUNG Galaxy Z Flip3 5G 8GB+256GB 折叠屏5G手机 立式交互体验 IPX8防水 梦境极光",
            "skuShortName": "电池"
        }]}

with open(json_path, "r", encoding="utf-8") as f:
    datas = json.load(f)["RECORDS"]


def gen_data(_long: str, _short: str) -> dict:
    d = {
        "instruction": "请针对以下商品名称生成商品简称，并直接给出答案",
        "input": _long,
        "output": _short
    }
    return d


for data in datas:
    desc = data.get("skuDesc", "")
    name = data.get("skuName", "")
    short = data.get("skuShortName", "")
    if not short:
        continue
    if desc:
        dd = gen_data(desc, short)
        result.append(dd)
    if name:
        dd = gen_data(name, short)
        result.append(dd)

with open("./short_name_10k.json", "w", encoding="utf-8") as f:
    json.dump(result[:10000], f, ensure_ascii=False)

print("result.count =", len(result))

